package com.example.clsj;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.example.clsj.dto.DrugDetailDto;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import io.netty.handler.codec.haproxy.HAProxyMessage;
import lombok.Cleanup;
import lombok.SneakyThrows;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommonTest2 {

    private static final String CHARSET_UTF_8 = "UTF-8";

    private static TimeInterval timer = null;

    @Before
    public void beforeTest() {
        timer = DateUtil.timer();
    }

    @After
    public void afterTest() {
        long hs = timer.intervalMs();
        System.out.println(StrUtil.format("耗时：{}.{}s", hs / 1000, hs % 1000));
    }

    @Test
    @SneakyThrows
    public void test1() {
        String str1 = FileUtil.readString(new File("doc/1.txt"), StandardCharsets.UTF_8);
        String str2 = FileUtil.readString(new File("doc/2.txt"), StandardCharsets.UTF_8);
        JSONArray objects1 = JSONUtil.parseArray(str1);
        JSONArray objects2 = JSONUtil.parseArray(str2);

        Map<String, Integer> map1 = new HashMap<>();

        for (Object o : objects1) {
            JSONObject entries = JSONUtil.parseObj(o);
            map1.put(entries.getStr("jobNumber"), map1.getOrDefault(entries.getStr("jobNumber"), 0));
        }

        for (Object o : objects2) {
            JSONObject entries = JSONUtil.parseObj(o);
            map1.put(entries.getStr("jobNumber"), map1.getOrDefault(entries.getStr("jobNumber"), 0) + 1);
        }

        System.out.println(JSONUtil.toJsonStr(map1));
    }

    @Test
    @SneakyThrows
    public void test2() {

        // 1. 指定输出文件路径
        String dest = "C:\\Users\\admin\\Desktop\\yzj\\example.pdf";

        // 2. 创建 Document 对象
        Document document = new Document();

        // 3. 创建 PdfWriter 对象并关联到 Document 和文件输出流
        PdfWriter.getInstance(document, Files.newOutputStream(Paths.get(dest)));

        // 4. 打开文档
        document.open();

        // 5. 添加内容到文档
        document.add(new Paragraph("扬子江药业集团江苏龙凤堂中药有限公司"));
        document.add(new Paragraph("扬子江药业集团江苏制药股份有限公司"));
        document.add(new Paragraph("扬子江药业集团北京海燕药业有限公司"));

        // 6. 关闭文档
        document.close();

        System.out.println("PDF 文件已成功生成：" + dest);


    }


    @Test
    @SneakyThrows
    public void test3() {

    }

}
